﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LinQProject;
using LinQProject.Repository;

namespace ServiceProject.EntityService
{
    public class ConversationService : DataBaseProcessBase<Conversation>
    {
        public ConversationService(FarmacieDataClassesDataContext database) : base(database)
        {
        }

        public bool InsertUpdate(Conversation conversationItem, out int id,out Exception eroare )
        {
            eroare = null;
            id = 0;
            if (conversationItem.ConversationId==0)
            {
               try
               {
                   id=(int)base.Add(conversationItem, "ConversationId");
               }
                catch(Exception exc)
                {
                    eroare = exc;
                    return false;
                }
            }
            else
            {
                try
                {
                    base.Update(conversationItem, c=>c.ConversationId==conversationItem.ConversationId);
                }
                catch(Exception exc)
                {
                    eroare = exc;
                    return false;
                }
            }
            return true;
        }
    }
}
